package com.guan.ordering_sys.generator.controller;


import com.guan.ordering_sys.common.PageResult;
import com.guan.ordering_sys.common.ResultApi;
import com.guan.ordering_sys.generator.entity.Goods;
import com.guan.ordering_sys.generator.service.impl.GoodsServiceImpl;
import com.guan.ordering_sys.param.GoodsUpdateParam;
import com.guan.ordering_sys.param.PageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  GoodsController 前端控制器
 * </p>
 *
 * @author 关远键
 * @version v1.0.2
 * @since 2021-06-18
 */
@Api(tags = "商品控制器")
@RestController
@RequestMapping("/api/goods")
public class GoodsController {

    @Autowired
    GoodsServiceImpl goodsService;

    @ApiOperation("商品列表")
    @GetMapping("/getList")
    public ResultApi getGoodList(PageParam pageParam){
        PageResult pageResult = goodsService.getList(pageParam);
        return ResultApi.success(pageResult);
    }

    @ApiOperation("商品详情")
    @GetMapping("/getGoodsById/{id}")
    public ResultApi getGoodsById(@PathVariable("id") Long id) {
        return ResultApi.success(goodsService.getGoodsById(id));
    }


    @ApiOperation("添加商品")
    @PostMapping("/add")
    public ResultApi add(Goods param, MultipartFile picture) {
        return ResultApi.success(goodsService.insert(param, picture));
    }

    @ApiOperation("更新商品")
    @PatchMapping("/updateById")
    public ResultApi updateById(GoodsUpdateParam param, MultipartFile picture) {
        return ResultApi.success(goodsService.updateById(param, picture));
    }

    @ApiOperation("删除商品")
    @DeleteMapping("/deleteById/{id}")
    public ResultApi deleteById(@PathVariable("id") Long id) {
        return ResultApi.success(goodsService.deleteById(id));
    }

}

